package game.targets.entity;

import game.targets.Constants;
import game.targets.observer.Subject;

import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.math.Vector3;

public abstract class Entity implements Constants {

	protected boolean exists;
	protected float scale;
	protected GraphicsComponent graphics;
	protected Subject subject;
	protected Vector3 position;
	protected Vector3 direction;

	public Entity(Vector3 pos, Vector3 rotation, Vector3 graphicRotation, String path, Subject subject) {
		exists = true;
		scale = 1;
		position = pos;
		this.subject = subject;
		direction = new Vector3(rotation);
		graphics = new GraphicsComponent(position, graphicRotation, path, scale);
	}

	public Entity(Vector3 pos, Vector3 rotation, String path, Subject subject) {
		this(pos, rotation, rotation, path, subject);
	}

	public abstract void update(float delta);

	public void render(ModelBatch batch, Environment environment) {
		graphics.render(this, batch, environment);
	}

	public void setInvisible(boolean i) {
		graphics.setInvisible(i);
	}

	public void dispose() {
		graphics.dispose();
	}

	public void delete() {
		exists=false;
		prepForDeletion();
		// graphics.dispose();
	}

	public void prepForDeletion() {

	}

	public boolean isExists() {
		return exists;
	}

	public void setExists(boolean exists) {
		this.exists = exists;
	}

	public float getScale() {
		return scale;
	}

	public void setScale(float scale) {
		this.scale = scale;
		if (graphics.getInstance() != null) {
			graphics.setScale(scale);
		}
		// setPhysicsScale(scale);
	}

	public void setScale(float x, float y, float z) {
		if (graphics.getInstance() != null) {
			graphics.setScale(x, y, z);
		}
		// setPhysicsScale(scale);
	}

	public void rotate(Vector3 axis, float angle) {
		graphics.rotate(axis, angle);
	}

	public void setPhysicsScale(float scale) {

	}

	public Vector3 getPosition() {
		return position;
	}

	public void setPosition(Vector3 position) {
		this.position.set(position);
		graphics.setPosition(position);
	}

	public GraphicsComponent getGraphics() {
		return graphics;
	}

	public void setGraphics(GraphicsComponent graphics) {
		this.graphics = graphics;
	}

}
